{% extends 'base.html' %}

{% block title %}{{ book.title }}{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-4">
        {% if book.cover %}
        <img src="{{ book.cover.url }}" class="img-fluid rounded" alt="{{ book.title }}">
        {% else %}
        <div class="bg-secondary text-white p-5 text-center rounded">
            暂无封面
        </div>
        {% endif %}
    </div>
    <div class="col-md-8">
        <h2>{{ book.title }}</h2>
        <table class="table">
            <tr>
                <th>作者</th>
                <td>{{ book.author }}</td>
            </tr>
            <tr>
                <th>出版社</th>
                <td>{{ book.publisher }}</td>
            </tr>
            <tr>
                <th>出版日期</th>
                <td>{{ book.publish_date }}</td>
            </tr>
            <tr>
                <th>ISBN</th>
                <td>{{ book.isbn }}</td>
            </tr>
            <tr>
                <th>分类</th>
                <td>{{ book.get_category_display }}</td>
            </tr>
            <tr>
                <th>状态</th>
                <td>
                    <span class="badge bg-{% if book.status == 'available' %}success{% elif book.status == 'borrowed' %}danger{% else %}warning{% endif %}">
                        {{ book.get_status_display }}
                    </span>
                </td>
            </tr>
        </table>
        
        <h4>描述</h4>
        <p>{{ book.description|default:"暂无描述" }}</p>
        
        <div class="mt-4">
            {% if user.is_authenticated %}
                {% if book.status == 'available' and not is_borrowed %}
                <a href="{% url 'books:borrow_book' book.pk %}" class="btn btn-success">借阅</a>
                {% elif is_borrowed %}
                <a href="{% url 'books:return_book' book.pk %}" class="btn btn-warning">归还</a>
                {% endif %}
            {% else %}
            <p class="text-muted">请登录后借阅图书</p>
            {% endif %}
            <a href="{% url 'books:book_list' %}" class="btn btn-secondary">返回列表</a>
        </div>
    </div>
</div>
{% endblock %}